package com.yztc.orangeentertainment.ui.main.findfragment.findadapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yztc.orangeentertainment.R;
import com.yztc.orangeentertainment.bean.findbean.FindHotDataListBean;
import com.yztc.orangeentertainment.ui.main.findfragment.findmain.FindHotActivity;
import com.yztc.orangeentertainment.ui.main.findfragment.findutils.CustomShapeTransformation;
import com.yztc.orangeentertainment.ui.main.channalarticle.ChannalArticleActivity;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by My on 2016/10/15.
 */
public class FindHotAdapter extends RecyclerView.Adapter<FindHotAdapter.HotViewHolder> {
    private Context context;
    private List<FindHotDataListBean> list;

    public FindHotAdapter(Context context, List<FindHotDataListBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public HotViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        HotViewHolder holder = new HotViewHolder(LayoutInflater.from(context).inflate(R.layout
                .findhot_rlv, null));
        return holder;
    }

    @Override
    public void onBindViewHolder(HotViewHolder holder, final int position) {
        if (position == 0) {
            holder.hot.removeAllViewsInLayout();
            Glide.with(context).load(list.get(position).getPic()).into(FindHotActivity.findhotIv);
            FindHotActivity.findhotTitle.setText(list.get(position).getTitle());
            FindHotActivity.findhotName.setText(list.get(position).getCat().getName());
            Glide.with(context).load(list.get(position).getCat().getIcon()).bitmapTransform(new
                    CustomShapeTransformation(context, R.mipmap
                    .abc_btn_switch_to_on_mtrl)).into(FindHotActivity
                    .findhotIcon);
            FindHotActivity.findhotNum.setText(list.get(position).getReadnum() + "");

            FindHotActivity.findhotHead.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, ChannalArticleActivity.class);
                    intent.putExtra("id", list.get(position).getId() + "");
                    context.startActivity(intent);
                }
            });
        } else {
            Glide.with(context).load(list.get(position).getPic()).into(holder.hotIv);
            holder.hotTitle.setText(list.get(position).getTitle());
            holder.hotName.setText(list.get(position).getCat().getName());
            Glide.with(context).load(list.get(position).getCat().getIcon()).bitmapTransform(new
                    CustomShapeTransformation(context, R.mipmap
                    .abc_btn_switch_to_on_mtrl)).into(holder.hotIcon);
            holder.hotNum.setText(list.get(position).getReadnum() + "");

            holder.hot.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, ChannalArticleActivity.class);
                    intent.putExtra("id", list.get(position).getId() + "");
                    context.startActivity(intent);
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class HotViewHolder extends RecyclerView.ViewHolder {
        @InjectView(R.id.hot_iv)
        ImageView hotIv;
        @InjectView(R.id.hot_title)
        TextView hotTitle;
        @InjectView(R.id.hot_icon)
        ImageView hotIcon;
        @InjectView(R.id.hot_name)
        TextView hotName;
        @InjectView(R.id.hot_num)
        TextView hotNum;
        @InjectView(R.id.hot)
        RelativeLayout hot;

        public HotViewHolder(View itemView) {
            super(itemView);
            ButterKnife.inject(this, itemView);
        }
    }
}
